package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.R.R;
import net.wanho.dto.OutStoreAddDTO;
import net.wanho.dto.OutStoreConfirmDTO;
import net.wanho.dto.OutStoreDTO;
import net.wanho.dto.OutStoreExportDTO;
import net.wanho.service.OutStoreService;
import net.wanho.vo.OutStoreExportVO;
import net.wanho.vo.OutStoreVO;
import net.wanho.vo.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 这个类是：
 *
 * @author: MENG HU WANG
 * @date: 2025/2/6 16:15
 * @version: 1.0
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("outstore")
public class OutStoreController {

    private final OutStoreService outStoreService;

    // 分页查询出库单
    @RequestMapping("outstore-page-list")
    public R getOutStorePageList(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "5") Integer pageSize,
                                 OutStoreDTO outStoreDTO) {
        PageInfo<OutStoreVO> outStorePageList = outStoreService.getOutStorePageList(pageNum, pageSize, outStoreDTO);
        return R.ok(outStorePageList);
    }

    // 添加出库单
    @PostMapping("outstore-add")
    public R addOutStorePage(@RequestBody OutStoreAddDTO outStoreAddDTO) {
        outStoreService.addOutStorePage(outStoreAddDTO);
        return R.ok("添加出库单成功！");
    }

    // 确认出库
    @PutMapping("outstore-confirm")
    public R confirmOutStore(@RequestBody OutStoreConfirmDTO confirmDTO) {
        outStoreService.confirmOutStore(confirmDTO);
        return R.ok("确认出库成功！");
    }

    // 导出数据
    @GetMapping("exportTable")
    public R exportTable(@RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize,
                         OutStoreExportDTO exportDTO) {
        List<OutStoreExportVO> list = outStoreService.exportTable(pageNum, pageSize, exportDTO);
        return R.ok(list);
    }
}
